<?php


class ZFile {

	/**
	 * 根据文件生成一个文件信息对象
	 * @param  [file] $file [description]
	 * @return [object]       [description]
	 */
	static public function makeFileData($file_path)
	{
		return new FileObj($file_path);
	}

	/**
	 * 获取上传的文件 放到指定位置 storage to db.
	 * @param  [type] $file [$_FIILES]
	 * @return [type]       [description]
	 */
	public function uploadFile($file)
	{

	}

	public function moveFile($file_path)
	{

	}

	public function urlFile($fileUrl)
	{
		
	}
}


/**
 * file Info & hash
 */
class fileObj {

	public $file;

	public $filename;

	public $filesize;

	public $mime;

	public $file_hash;

	protected $algo;

	public function __construct($file, $algo = 'sha512')
	{
		$this->file = $file;
		$this->algo = $algo;

		$this->filename = basename($file);
		$this->filesize = filesize($file);
		$this->mime = (new finfo(FILEINFO_MIME_TYPE))->file($file);
		$this->file_hash = $this->hashValue();
	}

	public function hashValue()
	{
		return hash_file($this->algo, $this->file);
	}
}

// $a = hash_file('md5', '1.mp4');echo $a;echo "<br>";
// $b = hash_file('sha1', '1.mp4');echo $b;echo "<br>";
// $c = hash_file('sha512', '1.mp4');echo $c;echo "<br>";
